package com.clkj.sunhelp.adapter.grid;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.bean.PolicyKindItem;
import com.clkj.sunhelp.common.Config;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/3/26.
 */

public class GridAdapterForPolicyKind extends BaseAdapter {


    List<PolicyKindItem> mPolicyKindList;
    Context mContext;
    LayoutInflater mLayoutInflater;

    public GridAdapterForPolicyKind(Context context, List<PolicyKindItem> policyKindList) {
        mContext = context;
        mPolicyKindList = policyKindList;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mPolicyKindList.size();
    }

    @Override
    public Object getItem(int i) {
        return mPolicyKindList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null)
        {
            view = mLayoutInflater.inflate(R.layout.list_item_policy_kind,null);
            viewHolder = new ViewHolder();
            viewHolder.tvPolicyKindname = (TextView) view.findViewById(R.id.tv_policy_kindname);
            viewHolder.ivPolicyKind = (ImageView) view.findViewById(R.id.iv_policy_kind);

            view.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.tvPolicyKindname.setText(mPolicyKindList.get(i).getItemName());
        Picasso.with(mContext).load(Config.URL_BASE_IN_USE+mPolicyKindList.get(i).getIcon()).
                placeholder(R.drawable.ico_policy_kind).
                error(R.drawable.ico_policy_kind).
                tag(mContext).
                into(viewHolder.ivPolicyKind);

        return view;
    }


    static class ViewHolder{
        private ImageView ivPolicyKind;
        private TextView tvPolicyKindname;






    }
}
